package com.atguigu.gulimall.order.web;

import com.atguigu.gulimall.order.entity.OrderEntity;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @Author : Jungle
 * @Description :
 */
@Controller
public class HelloController {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    //简单视图通过配置文件
    //@GetMapping("/{page}")
    //public String toPage(@PathVariable("page") String page){
    //    return "page";
    //}


    @ResponseBody
    @GetMapping("/test/createOrder")
    public String createOrderTest(){
        //1、模拟下单成功
        OrderEntity orderEntity = new OrderEntity().setCreateTime(new Date()).setOrderSn(IdWorker.getTimeId());
        //2、发送消息
        // convertAndSend(String exchange, String routingKey, Object message)
        rabbitTemplate.convertAndSend("order-event-exchange","order.create.order",orderEntity);
        return "ok";

    }
}
